package com.app.twth.ui.tally.lpn;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.app.twth.databinding.ItemTallyLpnListBinding;
import com.app.twth.interfaces.MyStringOnClickListener;

import java.util.ArrayList;
import java.util.List;


public class TallyLPNAdapter extends RecyclerView.Adapter<TallyLPNAdapter.MyViewHolder> {
    private LayoutInflater mInflater;
    private List<TalliedSku> data = new ArrayList<>();
    private MyStringOnClickListener locationListener;

    public TallyLPNAdapter(Context mContext, List<TalliedSku> data, MyStringOnClickListener locationListener) {
        this.data = data;
        this.mInflater = LayoutInflater.from(mContext);
        this.locationListener = locationListener;
    }

    public void setData(List<TalliedSku> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(ItemTallyLpnListBinding.inflate(mInflater, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ItemTallyLpnListBinding itemBinding;

        public MyViewHolder(ItemTallyLpnListBinding itemBinding) {
            super(itemBinding.getRoot());
            this.itemBinding = itemBinding;
        }

        public void setData(int position) {
            itemView.setTag(position);
            TalliedSku tallyLPN = data.get(position);
            itemBinding.tvItem.setText(tallyLPN.getSku() + "");
            itemBinding.tvInventory.setText(tallyLPN.getQty() + "");
        }
    }
}
